import Vue from 'vue'
import Vuex from 'vuex'
import { setItem, getItem } from '@/utils/localStorage'

Vue.use(Vuex)

const USER_KEY = 'user'

export default new Vuex.Store({
    state: {
        user: getItem(USER_KEY)
    },
    mutations: {
        setUser(state, payload) {
            state.user = payload;
            //让数据持久化，保存到本地存储中
            setItem(USER_KEY, state.user)
        }
    },
    actions: {},
    modules: {}
})